-- Modificacion sql para cheques a vencer y en cartera -- 

-- Nori  04/12/2020

update srvpaqry set sql = 

'select sum(x.impo_cheque) as total_cheques
from
(
select ctem.idval, max(ctem.impo) as impo_cheque
from comm
join ambempsuc on comm.codambsuc = ambempsuc.codambsuc
join ctem on comm.id = ctem.idcomm
where comm.idpad = :IdPad and
ctem.tipovalt in (''CHE-T'', ''CHE-E'', ''ECH-T'') and
:SYS_Emp = ambempsuc.codambemp
group by 1
) x
join val on x.idval = val.id
left join pad on val.idpadquelotiene = pad.id
where (val.fechacobro > cast(now() as date)) or (pad.codpadr like ''F.CAJ%'')'

where cod = 'CC_ChAVencerYCartera';


--==================================
SELECT aaVersion('445.04','445.03');
--==================================
